# 购物系统业务需求V2.0
import  random
from datetime import datetime  # 导入datetime模块用于获取时间
money = float(input("有多少钱："))  # 账户里的钱
coupon = {
    'coupon1':{'desc':'1折','count':0.1,},
    'coupon2':{'desc':'2折','count':0.2,},
    'coupon3':{'desc':'3折','count':0.3,},
    'coupon4':{'desc':'4折','count':0.4,},
    'coupon5':{'desc':'5折','count':0.5,},
    'coupon6':{'desc':'6折','count':0.6,},
    'coupon7':{'desc':'7折','count':0.7,},
    'coupon8':{'desc':'8折','count':0.8,},
    'coupon9':{'desc':'9折','count':0.9,},
    'coupon10':{'desc':'免单','count':0,},
          }
user_cou = random.choice(list(coupon.values()))
com_list = ['面包','西瓜','草莓','白菜','胡萝卜','薯片','果冻','毛巾','水杯','书包'] # 商品列表
com_num = 0  # 商品数量
com_return = []  # 退货列表
price_return = 0
price_dic = {
     '商品':'价格',# 商品价格表
     '面包':5,
     '西瓜':10,
     '草莓':15,
     '白菜':3,
     '胡萝卜':5,
     '薯片':6,
     '果冻':5,
     '毛巾':2,
     '水杯':15,
     '书包':20
}

receipt_list = {}  # 购物小票字典
price_sum = 0
discount_price = 0
while True:
    if money < 0:
        print("没钱，go away")
        break
    else:
       want = input('你想买什么：')
       if want in com_list:
                  print("有这个商品")
                  price =float(price_dic[want])
                  print("这件商品的价格是：{}".format(price))
                  if price <= money:
                           receipt_list.update({want:price})
                           com_num += 1
                           print('添加到购物车！还想买点别的吗？yes/no')
                           price_sum = price_sum + price
                           receipt_list.update({want: price})
                           if input() =='no':
                              print('你有想要退的商品吗？y/n')  # 添加退货功能
                              if input() == 'y':
                                  while True:
                                      com_return = input('你要退什么？')
                                      if com_return in receipt_list:
                                              price_return = float(price_dic[com_return])
                                              del receipt_list[com_return] # 从小票里把退货删除
                                              price_sum = price_sum - price_return
                                              print('退货成功')
                                              com_num -= 1
                                              break
                                      else:
                                              print('没有这个商品')
                              discount_price = price_sum * user_cou['count']
                              money = money - discount_price
                              break
                  else:
                           print('穷鬼，钱不够！请到其他超市购买！')
                           break
       else:
          print('没有这个商品，别瞎弄！')
          break

print('你抽到了优惠券：{}，可以打折'.format(user_cou))
if input('输入Q退出') == 'q' or 'Q':
        print("现在是北京时间：{}\n恭喜，购买成功！你的购物小票：\n".format(datetime.now()))
        for re_key, re_info in receipt_list.items():
            print('商品：{}，价格：{}\n'.format(re_key, re_info))
        print('总计：{}元\n一共{}件商品\n折后价：{}\n您的卡余额还剩:{}'.format(price_sum, com_num, discount_price, money))